<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div>1</div>
    <div>2</div>
    <div>3</div>
</body>
<script type="module" src="../static/main.js"></script>
<script>
    // 父类有加法方法
    class Father {
        constructor(x, y) {
            this.x = x;
            this.y = y;
        }
        sum() {
            console.log(this.x + this.y);
        }
    }
    class Son extends Father{
        constructor(a,b) {
            super(a,b);
            this.a = a
            this.b = b
        }
        sub() {
            console.log(this.b-this.a)
        }
    }
    var son = new Son(1,2);
    son.sum()
    son.sub()


    class Clazz {
        constructor(name,age,sex) {
            this.name = name
            this.age = age
            this.sex = sex
        }
        eat() {

        }
    }
    var clazz1 = new Clazz("w",10,"nan");
    console.log(clazz1)

    let target = {a:1}
    let source1 = {b:2}
    let source2 = {a:4,c:3}
    // let assign = Object.assign(target,source1,source2);
    // console.info(assign)
    let assign = {...source2,...source1,...target}
    console.log(assign)


    let name = "wang"
    let ld={
        name:"li",
        age: 20,
        eat: function () {

        },
        eat1:()=>{},
        eat2() {

        },
    }
    ld.name = name

    console.log(Object.keys(ld))
    console.log(Object.values(ld))
    console.log(Object.entries(ld))


    let map = new Map([['name','张三'],[{name:'jack'},{height:175, sex:'男' }]]);
    let obj = {};
    map.forEach((item, key) => {
        if(typeof key != 'string'){
            key = JSON.stringify(key);
        }
        obj[key] = item;
    });
    console.log(obj)

    // let map = new Map([['name','jack'],['age',18]]);
    // // map.forEach((value,key,map)=>console.log(map))
    // for (let mapElement in map) {
    //     console.log(mapElement)
    // }

    const set = new Set([1, 2, 3, 4, 4]);//{1, 2, 3, 4}
    console.log(set)
    set.forEach(item=>console.log(item))


    // let name = "lisi" +
    //     "zhangsan"

    let str = `名字是${name}
    hh`
    console.log(str)


    let ary = [{
        id: 1,
        name: '张三'
    }, {
        id: 2,
        name: '李四'
    }];
    var find = ary.find((item,index)=>index===0);
    console.log(find)


    let oDivs = document.getElementsByTagName('div');
    console.log(oDivs)
    oDivs = [...oDivs];
    console.log(oDivs)

    let array = [1,2,3]
    console.log(...array)
    console.log(1,2,3)

    var age = 100;
    // var obj = {
    //     age: 20,
    //     say: () => {
    //         alert(obj.age)
    //     }
    // }
    // obj.say()

    // let obj = {
    //     name : "lisi",
    //     eat: function () {
    //         console.log(this)
    //     },
    // }
    // obj.eat()

    function fn(a,b=1) {
        console.log(this)
        console.log(a+b)
        return ()=>{
            console.log(this)
        }
    }
    fn(1)
    var fn2 = fn.call(obj)
    fn2()

    let arr1 = [0, 1]
    // let fn =  (a,b)=>{
    //     console.log(this)
    //     return a+b
    // }
    var fn1 = fn(1,2);
    console.log(fn1)

    // console.log(arr1[0] )
    // console.log(arr1[1])

    // 数组解构
    let [a, b, c] = arr1
    // console.log(a)
    // console.log(b)
    // console.log(c)

    // 对象解构
    // let obj = {
    //     name1: "lisi",
    //     age: 18
    // }
    // console.log(obj.name)
    // console.log(obj.age)

    let {name1: n, age: a1, age1} = obj
    // console.log(name1)
    // console.log(age)
    // console.log(age1)

    console.log(n)
    console.log(a1)


    var arr = [];
    for (let i = 0; i < 2; i++) {
        arr[i] = function () {
            console.log(i);
        }
    }
    // arr[0](); //0
    // arr[1](); //1

    const num = "str"


    if (true) {
        // var a =10
    }
    // 块级作用域
    // 不存在变量提升
    // console.log(a)
    // var a = 10
    // var a = 9
    // console.log(a)
</script>
</html>